import pymysql

class DB:
    def __init__(self):
        self.conn = pymysql.connect(
            host='localhost',
            port=3306,
            user='root',
            password='123',
            db='workf',
            charset='utf8',
            cursorclass=pymysql.cursors.DictCursor
            )
        # 创建游标
        self.course = self.conn.cursor()

    # 添加  修改  删除
    def intsert(self,sql):
        self.course.execute(sql)
        self.conn.commit()
        return 'OK 成功'

    # 查找单个数据
    def find(self,sql):
        self.course.execute(sql)
        res = self.course.fetchone()
        return res

    # 查询所有
    def fingall(self,sql):
        self.course.execute(sql)
        res = self.course.fetchall()
        return res

db1 = DB()
